<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言板</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .ad{
            position: relative;
            margin: 100px auto;
            width: 600px;
            height: 500px;
            border: 1px solid black;
            background:url("1.jpg") no-repeat center/100% 100%;
            /* display: none; */
        }
        .ad .close{
            position: absolute;
            top: 5px;
            right: 5px;
            width: 30px;
            height:30px;
            line-height: 30px;
            text-align: center;
            border: 1px solid white;
            font-size: 32px;
        }
        
    </style>
</head>
<body>
    <div class="ad">1</div>
    <div class="ad">2</div>
    <div class="ad">3
        <!-- 这是注释语句 -->
        <h3 class="close">x</h3>
        <h3 class="close2">x</h3>
        <h3 class="close3">x</h3>
    </div>
    <script>
        const a = document.querySelectorAll('.ad');
        let list=a[1].nextElementSibling.children;
        console.log(list[0]);
    </script>
    <script>

        const clo=document.querySelector('.close');//获取close关闭元素节点
        const ad=document.querySelectorAll('.ad');//获取类名ad的元素节点
        // const ad=document.querySelector('.ad');
            
        //给关闭按钮添加监听事件
        clo.addEventListener('click',function(){
            //事件处理程序
            clo.parentElement.style.display='none';
            // ad[2].style.display='none';
        },false);
        console.log(clo.parentNode);
        console.log(clo.parentElement);
        console.log('---------------');
        console.log(ad[2].childNodes);
        console.log(ad[2].children);
        console.log('---------------');
        console.log(clo.previousElementSibling);
        console.log(clo.nextElementSibling);
    </script>
</body>
</html>